#include <unistd.h>
#include <stdio.h>

int copyfile(int formfd, int tofd){
	char buf[1024];
	int n;

	n = read(formfd, buf, sizeof(buf));
	if(n == -1){
		perror("read error!");
		return -1;
	}

	n = write(tofd, buf, n);
	if(n == -1){
		perror("write error");
		return -1;
	}

	return n;
	
}

int main(void){
	int numbytes;

	numbytes = copyfile(STDIN_FILENO, STDOUT_FILENO);
	fprintf(stderr, "Number of bytes copied: %d\n", numbytes);
	return 0;
}
